<template>
  <a-card>
    <a-modal
      title="挂号管理"
      :width="800"
      :visible="modalMisible"
      :plain="true"
      :model="forms"
      @ok="submitOk"
      @cancel="modalMisible=false"
    >
      <a-form :form="form">
        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="号源医院" :required="true" hasFeedback>
          <a-select v-model="forms.registerHospitalId" style="width: 300px;">
            <a-select-option v-for="(item,index) in hospitals" :value="item.id" :key="item.id" @click="selectHospital(item)">{{ item.name }}</a-select-option>
          </a-select>
        </a-form-item>

<!--        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="科室" :required="true" hasFeedback>-->
<!--          <a-select v-model="forms.department">-->
<!--            <a-select-option v-for="(item,index) in departments" :value="item.id" :key="item.id" @click="selectDepartment(item)">{{ item.name }}</a-select-option>-->
<!--          </a-select>-->
<!--        </a-form-item>-->

        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="选择号种" :required="true" hasFeedback>
          <a-select v-model="forms.type">
            <a-select-option value="普通号">普通号</a-select-option>
            <a-select-option value="专家号">专家号</a-select-option>
            <a-select-option value="特需号">特需号</a-select-option>
          </a-select>
        </a-form-item>

        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="日期" :required="true" hasFeedback>
          <j-date placeholder="请选择日期" v-model="forms.visitTime" :trigger-change="true" style="width: 100%"/>
        </a-form-item>

        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="时间段" :required="true" hasFeedback>
          <a-select v-model="forms.visitPart">
            <a-select-option value="上午">上午</a-select-option>
            <a-select-option value="下午">下午</a-select-option>
            <a-select-option value="晚上">晚上</a-select-option>
          </a-select>
        </a-form-item>

        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="开始序号（包含开始）" :required="true" hasFeedback>
          <a-input v-model="forms.numStart" placeholder="请输入号源开始序号" :min="0" :max="1000" type="number"/>
        </a-form-item>

        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="结束序号（包含结束）" :required="true" hasFeedback>
          <a-input v-model="forms.numEnd" placeholder="请输入号源结束序号" :min="0" :max="1000" type="number"/>
        </a-form-item>

        <a-form-item
          label="价格"
          :required="true"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          hasFeedback
          validateStatus="success">
          <a-input placeholder="请输入价格" :min="0" :max="1000" prefix="￥" type="number" v-model.number="forms.price" />
        </a-form-item>

      </a-form>
    </a-modal>

  </a-card>
</template>

<script>
import { httpAction, getAction,putAction } from '@api/manage'
import JDate from '@/components/jeecg/JDate'
export default {
  name: 'DoctorRegisterEditModal',
  components: {
    JDate,
  },
  inject: ['reload'],

  data() {
    return {
      title: '挂号管理',
      modalMisible: false,
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      labelCols: {
        xs: { span: 12 },
        sm: { span: 8 },
      },
      wrapperCols: {
        xs: { span: 12 },
        sm: { span: 10 },
      },
      forms:{
        doctorId: '',
        registerHospitalId: "",
        department: '',
        type: '',
        visitTime: '',
        visitPart: '',
        numStart: 0,
        numEnd: 0,
        count: 0,
        price: '',
      },
      hospitals:{},  //医院信息
      // departments:{},//可是信息
      form: this.$form.createForm(this),
      validatorRules: {
        share: {
          rules: [
            { required: true, message: '请输入数字值'},
          ]
        },
      },
      url: {
        add: "/doctorRegister/doctorRegister/add",
        editSave: "/doctorRegister/doctorRegister/edit",
      },
    }
  },
  created() {

  },
  methods: {
    viewShow(record) {
      this.forms = {
        doctorId:record.doctorId,
        registerHospitalId: record.registerHospitalId,
        department: record.departmentId,
        type:record.type,
        visitTime: record.visitTime,
        visitPart: record.visitPart,
        numStart: record.numStart,
        numEnd: record.numEnd,
        count: record.count,
        price: record.price,
        createTime:record.createTime,
        createUser:record.createUser,
        id:record.id,
      }
      getAction(this.url.add).then(res => {
        this.hospitals   = res.result.hospitals;
        // this.departments = res.result.departments;
      })

      this.modalMisible = true
    },
    //选择医院
    selectHospital(hospital){
      this.forms.registerHospitalId = hospital.id;
    },
    //选择科室
    // selectDepartment(department){
    //   this.forms.department = department.id;
    // },

    submitOk () {
      var forms = this.forms;
      this.forms.count = forms.numEnd - forms.numStart + 1 - 0
      this.forms.numStart = this.forms.numStart - 0
      this.forms.numEnd = this.forms.numEnd - 0
      httpAction(this.url.editSave, this.forms,'put').then((res)=>{
        if(res.code === 200){
          this.$message.success(res.message)
          this.reload()
        }else{
          this.$message.warning(res.message)
        }
      }).catch((error)=>{
        console.log(error);
      })
    },
  }
}
</script>

<style lang="less" scoped>
  .ant-input-number {
    margin-right: 20px;
    width: 360px;
  }

</style>